package com.sgb.packers.view.adapter;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.packers.BR;
import com.sgb.packers.R;
import com.sgb.packers.databinding.PackersItemWorkStatisticsBinding;
import com.sgb.packers.entity.WorkStatisticsEntity;

import java.util.List;
import java.util.Locale;

/**
 * 描述：工队-记工统计设配器
 *
 * @author qiangHeNoo
 * <p>
 * 时间：2021.12.06
 */
public class WorkStatisticsAdapter extends BaseQuickAdapter<WorkStatisticsEntity, BaseViewHolder> {

    public WorkStatisticsAdapter(List<WorkStatisticsEntity> data) {
        super(R.layout.packers_item_work_statistics, data);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(BaseViewHolder helper, WorkStatisticsEntity item) {
        PackersItemWorkStatisticsBinding dataBinding = DataBindingUtil.bind(helper.itemView);
        if (null != dataBinding) {
            dataBinding.setVariable(BR.viewModel, item);
            dataBinding.executePendingBindings();
            dataBinding.packersProjectName.setText(item.getProjectName());
            if (item.getWorkStatisticsDataVO().getPointWorkStatisticsVo() == null) {
                dataBinding.clWork.setVisibility(View.GONE);
            } else {
                StringBuilder stringBuilder = new StringBuilder();
                if (!TextUtils.isEmpty(item.getWorkStatisticsDataVO().getPointWorkStatisticsVo().getWorkDayAll())) {
                    stringBuilder.append(item.getWorkStatisticsDataVO().getPointWorkStatisticsVo().getWorkDayAll()).append("个工");
                }
                if (!TextUtils.isEmpty(item.getWorkStatisticsDataVO().getPointWorkStatisticsVo().getWorkHourAll())) {
                    stringBuilder.append(",").append(item.getWorkStatisticsDataVO().getPointWorkStatisticsVo().getWorkHourAll()).append("小时");
                }
                dataBinding.packersTvWorkTime.setText(stringBuilder.toString());
                StringBuilder stringBuilder1 = new StringBuilder();
                if (!TextUtils.isEmpty(item.getWorkStatisticsDataVO().getPointWorkStatisticsVo().getWorkOverHourAll())) {
                    stringBuilder1.append(item.getWorkStatisticsDataVO().getPointWorkStatisticsVo().getWorkOverHourAll()).append("小时");
                    dataBinding.packersTvOverTime.setText(stringBuilder1.toString());
                } else {
                    dataBinding.packersTvOverTime.setText("0小时");
                }
                dataBinding.clWork.setVisibility(View.VISIBLE);
            }

            if (item.getWorkStatisticsDataVO().getWrapWorkStatisticsVo() == null) {
                dataBinding.clContractor.setVisibility(View.GONE);
            } else {
                dataBinding.packersTvContractor.setText(String.format(Locale.CHINA,"%.0f笔",item.getWorkStatisticsDataVO().getWrapWorkStatisticsVo().getWrapWorkNum()));
                dataBinding.clContractor.setVisibility(View.VISIBLE);

                dataBinding.packersTvContractorMoney.setText(item.getWorkStatisticsDataVO().getWrapWorkStatisticsVo().getSalaryAll() + "元");
            }

            if (item.getWorkStatisticsDataVO().getWrapWorkStatisticsVo() == null || item.getWorkStatisticsDataVO().getPointWorkStatisticsVo() == null) {
                dataBinding.packersViewLine.setVisibility(View.GONE);
            } else {
                dataBinding.packersViewLine.setVisibility(View.VISIBLE);
            }
        }

    }

}
